#include <stdlib.h>
#include <unistd.h>
#include <caml/mlvalues.h>
#include <caml/callback.h>

value isEmpty (value v)
{
    if ( Is_long(v) )
        return Val_int(1);
    return Val_int(0);
}

value len (value v)
{
    int                 i;
    for ( i = 0; !Int_val(isEmpty(v)); v = Field(v, 1))i++;
    return Val_int(i);
}

value sum (value v)
{
    int                 val;
    val = 0;
    for (; !Int_val(isEmpty(v)); v = Field(v, 1))
    {
        val = val + Int_val(Field(v, 0));
    }
    return Val_int(val);
}
